//
//  ChoseOtherViewController.m
//  marrymarry
//
//  Created by lsj on 16/9/26.
//  Copyright © 2016年 cf. All rights reserved.
//
static NSString * choseCellID = @"ChoseManyTableViewCell";
#import "ChoseOtherViewController.h"
#import "ChoseManyTableViewCell.h"
#import "CFinfoModel.h"
@interface ChoseOtherViewController ()
{
    NSString* _findStr;
}
@property (weak, nonatomic) IBOutlet UIButton *saveBtn;
@property (weak, nonatomic) IBOutlet UITableView *myTableView;
@property (weak, nonatomic) IBOutlet UILabel *myTitleLabel;
@property (nonatomic,strong) NSMutableArray * dataArry;
@property (nonatomic,strong) CFinfoModel * model;
@property (nonatomic,strong) NSMutableDictionary * otherDic;
@property (nonatomic,strong) NSArray * findStrArry;
@property (nonatomic,strong) NSMutableArray * currentArry;
@end

@implementation ChoseOtherViewController
-(NSMutableArray *)currentArry
{
    if (!_currentArry) {
        _currentArry = [NSMutableArray new];
        
    }
    return _currentArry;
}

-(NSMutableArray *)dataArry
{
    if (!_dataArry) {
       self.model = [CFinfoModel new];
        if (self.isLianRenXiangChu) {
            _dataArry = [[NSMutableArray alloc]initWithArray:self.model.thinkLianRenImpArry];
        }else if (self.isZuiKanZhong)
        {
            _dataArry = [[NSMutableArray alloc]initWithArray:self.model.zuiKanzhongArry];
        }else if (self.isDiaoDongInstert)
        {
            _dataArry = [[NSMutableArray alloc]initWithArray:self.model.diaoDongXingZhiArry];
        }else if (self.isAcceptPartner)
        {
            _dataArry = [[NSMutableArray alloc]initWithArray:self.model.CanJieShouArry];
        }
        else if (self.isFirstDateWantDo)
        {
           _dataArry = [[NSMutableArray alloc]initWithArray:self.model.firstMeetDoArry];
        }
        else if (self.isDatePlace)
        {
           _dataArry = [[NSMutableArray alloc]initWithArray:self.model.datePlaceArry];
        }else if (self.isRomance)
        {
            _dataArry = [[NSMutableArray alloc]initWithArray:self.model.dateRomanceArry];
        }
        else if (self.isInterestTalk)
        {
            _dataArry = [[NSMutableArray alloc]initWithArray:self.model.interestTalkArry];
        }
        else if (self.isWantToSport)
        {
           _dataArry = [[NSMutableArray alloc]initWithArray:self.model.likeSportArry];
        }else if (self.isQMFindOther)
        {
         _dataArry = [[NSMutableArray alloc]initWithArray:self.model.findOtherArry];
        }
        else{
        _dataArry = [[NSMutableArray alloc]initWithArray:self.model.findOtherArry];
        }
        
    }
    return _dataArry;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
     self.model = [CFinfoModel new];
    self.otherDic = [NSMutableDictionary new];
  
    if (self.isOther) {
        self.saveBtn.hidden = YES;
        
    }
    
    if (self.isZuiKanZhong) {
        _findStr = self.otherDic[MARRY_ONE_MOSTIMPORTANT_KEY];
        self.myTitleLabel.text = @"最看重对方那一点(多选)";
    }else if (self.isLianRenXiangChu)
    {
        self.myTitleLabel.text = @"认为两人相处最重要是(多选)";
        _findStr = self.otherDic[MARRY_TWO_MOSTIMPORTANT_KEY];
    }else if (self.isDiaoDongInstert)
    {
        self.otherDic = [self.model readTheUsualDicWithStr:MY_QINGMI_DIC];
        self.myTitleLabel.text = @"对方调动你的性致主要是(多选)";
        _findStr = self.otherDic[THINK_INTEREST_KEY];
    }else if (self.isAcceptPartner)
    {
        self.otherDic = [self.model readTheUsualDicWithStr:MY_QINGMI_DIC];
        self.myTitleLabel.text = @"能够接受伴侣(多选)";
        _findStr = self.otherDic[THINK_CAN_PARTNER_KEY];
    }
    else if (self.isQMFindOther)
    {
        self.otherDic = [self.model readTheUsualDicWithStr:MY_QINGMI_DIC];
        self.myTitleLabel.text = @"寻找的她/他应该是一位(多选)";
        _findStr = self.otherDic[FIND_OTHER_PEOPLE_MUST_BE_KEY];
    }
    else if (self.isFirstDateWantDo)
    {
        self.otherDic = [self.model readTheUsualDicWithStr:MY_DATE_DIC];
        self.myTitleLabel.text = @"初次约会希望做什么(多选)";
        _findStr = self.otherDic[FIRST_MEET_DO_KEY];
    }
    else if (self.isDatePlace)
    {
        self.otherDic = [self.model readTheUsualDicWithStr:MY_DATE_DIC];
        self.myTitleLabel.text = @"喜欢的约会场所(多选)";
        _findStr = self.otherDic[FIRST_MEET_LIKEPLACE_KEY];
    }else if (self.isRomance)
    {
        self.otherDic = [self.model readTheUsualDicWithStr:MY_DATE_DIC];
        self.myTitleLabel.text = @"交往中最浪漫的事情(多选)";
       _findStr = self.otherDic[FIRST_MEET_ROMANCE_KEY];
    }
    else if (self.isInterestTalk)
    {
        self.otherDic = [self.model readTheUsualDicWithStr:MY_DATE_DIC];
        self.myTitleLabel.text = @"感兴趣话题(多选)";
       _findStr = self.otherDic[FIRST_MEET_INTEREST_TALK_KEY];
    }
    else if (self.isWantToSport)
    {
        self.otherDic = [self.model readTheUsualDicWithStr:MY_DATE_DIC];
        self.myTitleLabel.text = @"愿意参与的体育运动(多选)";
        _findStr = self.otherDic[WILLING_TO_SPORT_KEY];
    }
    else{
          self.otherDic = [self.model readTheUsualDicWithStr:MY_ZEOU_DIC];
        self.myTitleLabel.text = @"寻找的她/他应该是一位(多选)";
    _findStr = self.otherDic[FIND_OTHER_PEOPLE_MUST_BE_KEY];
    }
    NSLog(@"findstr ===== %@",_findStr);
   self.findStrArry  = [NSArray new];
   self.findStrArry = [_findStr componentsSeparatedByString:@","];
    
    _currentArry = [[NSMutableArray alloc]initWithArray:self.findStrArry];
    if (_currentArry.count>0) {
        if ([_currentArry[0] isEqualToString:@""]) {
            [_currentArry removeObjectAtIndex:0];
        }
    }
    
}

#pragma mark UITableViewDatasource,UITableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
    
    
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArry.count;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
        ChoseManyTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:choseCellID];
        if (!cell) {
            cell = [[ChoseManyTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:choseCellID];
        }
    [cell reloadTheViewWithArry:self.dataArry andIndexPath:indexPath andSavedArry:_currentArry];

    if (self.isOther) {
        cell.userInteractionEnabled = NO;
    }
    return cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
        return 60;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([self.currentArry containsObject: self.dataArry[indexPath.row] ]) {
        [self.currentArry removeObject:self.dataArry[indexPath.row]];
       
    }else{
        [self.currentArry addObject:self.dataArry[indexPath.row]];
    }
    [self.myTableView reloadData];
    
    
}




#pragma mark ---------点击了返回
- (IBAction)gobackVC:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark ----------点击了保存
- (IBAction)selecetedSaveBtn:(UIButton *)sender {
    NSString * saveStr = [self.currentArry componentsJoinedByString:@","];
    if (self.isLianRenXiangChu) {
        [self.model saveTheusualDicDetialStr:saveStr andKeyStr:MARRY_TWO_MOSTIMPORTANT_KEY andDicName:MY_HUNYINGUANNIAN_DIC];
    }else if (self.isZuiKanZhong)
    {
        [self.model saveTheusualDicDetialStr:saveStr andKeyStr:MARRY_ONE_MOSTIMPORTANT_KEY andDicName:MY_HUNYINGUANNIAN_DIC];
    }
    else if (self.isDiaoDongInstert)
    {
        [self.model saveTheusualDicDetialStr:saveStr andKeyStr:THINK_INTEREST_KEY andDicName:MY_QINGMI_DIC];
    }
    else if (self.isAcceptPartner)
    {
        [self.model saveTheusualDicDetialStr:saveStr andKeyStr:THINK_CAN_PARTNER_KEY andDicName:MY_QINGMI_DIC];
    }
    else if (self.isQMFindOther)
    {
         [self.model saveTheusualDicDetialStr:saveStr andKeyStr:FIND_OTHER_PEOPLE_MUST_BE_KEY andDicName:MY_QINGMI_DIC];
    }
    else if (self.isFirstDateWantDo)
    {
        [self.model saveTheusualDicDetialStr:saveStr andKeyStr:FIRST_MEET_DO_KEY andDicName:MY_DATE_DIC];
    }
    else if (self.isDatePlace)
    {
        [self.model saveTheusualDicDetialStr:saveStr andKeyStr:FIRST_MEET_LIKEPLACE_KEY andDicName:MY_DATE_DIC];
    }else if (self.isRomance)
    {
        [self.model saveTheusualDicDetialStr:saveStr andKeyStr:FIRST_MEET_ROMANCE_KEY andDicName:MY_DATE_DIC];
    }
    else if (self.isInterestTalk)
    {
        [self.model saveTheusualDicDetialStr:saveStr andKeyStr:FIRST_MEET_INTEREST_TALK_KEY andDicName:MY_DATE_DIC];
    }
    else if (self.isWantToSport)
    {
        [self.model saveTheusualDicDetialStr:saveStr andKeyStr:WILLING_TO_SPORT_KEY andDicName:MY_DATE_DIC];
    }
    else{
    [self.model saveTheusualDicDetialStr:saveStr andKeyStr:FIND_OTHER_PEOPLE_MUST_BE_KEY andDicName:MY_ZEOU_DIC];
    
    }
    
    [self.navigationController popViewControllerAnimated:YES];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
